from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage
from page_object.login_page import LoginPage


class InformationPage(BasePage):
    url = r'/bsams/front/asset_user/user_info.do'

    # 定位密码
    pwd_btn_loc = (By.XPATH, '/html/body/div[1]/div/div[1]/a')
    pwd_old_loc = (By.ID, 'oldPassword')
    pwd_new_loc = (By.ID, 'newPassword1')
    pwd_new2_loc= (By.ID, 'newPassword2')
    pwd_ok_loc = (By.XPATH, '//*[@id="cboxLoadedContent"]/div/div/div[2]/div[4]/div[1]')
    # 定位手机号
    phone_id_loc = (By.ID, 'phone')
    phone_ok_loc = (By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[1]/form/table/tbody/tr[2]/td[3]/div/a')

    def change_pwd(self,oldPassword, newPassword1, newPassword2):
        self.open()
        self.ele_click(self.pwd_btn_loc)
        sleep(1)
        self.input_ele(self.pwd_old_loc, oldPassword)
        self.input_ele(self.pwd_new_loc, newPassword1)
        self.input_ele(self.pwd_new2_loc, newPassword2)
        sleep(1)
        self.ele_click(self.pwd_ok_loc)
        sleep(2)


    def change_phone(self,phone):
        self.open()
        self.ele_clear(self.phone_id_loc)
        self.input_ele(self.phone_id_loc, phone)
        self.ele_click(self.phone_ok_loc)
        sleep(2)
if __name__ == '__main__':
    oldPassword = '123456'
    newPassword1 = '123456'
    newPassword2 = '123456'
    phone = '134567842'


    chrome_location = r'D:\RJCS\谷歌浏览器内网通紫域和驱动安装\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)

    login_page = LoginPage(driver)
    login_page.login()

    information_page = InformationPage(driver)
    # information_page.change_pwd(oldPassword,newPassword1,newPassword2)
    information_page.change_phone(phone)